package 链表;

public class mergeTwoLists {
    public ListNode mergeTwoLists(ListNode list1, ListNode list2) {
        ListNode newNode = new ListNode(0);
        ListNode p=list1,q=list2,temp,tail;
        tail=newNode;
        while (p!=null && q!=null){
            if(p.val<q.val){
                temp=p.next;
                tail.next=p;
                p.next=null;
                p=temp;
                tail=tail.next;
            } else {
                temp=q.next;
                tail.next=q;
                q.next=null;
                q=temp;
                tail=tail.next;
            }
        }
        tail.next=(p!=null)?p:q;
        return newNode.next;
    }

    public static void main(String[] args) {
        ListNode node1 = new ListNode(0);
        ListNode node2 = new ListNode(0);
//        node1.next=node2;
        ListNode node3=node1;
        node3.next=node2;
        System.out.println(node3==node1);
    }
}
